<?php
$orderno = $_GPC['mid'];
$openid=$_W['openid'];
$result=$_GPC['result'];
$checkorder=pdo_fetch("select * from".tablename('tg_favorabler')."where  id='{$orderno}' ");

$sql = "SELECT * FROM " . tablename('tg_favorable') . " where id=:id";
$list = pdo_fetch($sql, array(':id' => $checkorder['favorable_id']));
$is_hexiao_member=1;
$tmparray = explode('|',$list['salesman']);
$saler=pdo_fetch('select * from '.tablename('tg_saler').' where openid=:openid and status=1',array(':openid'=>$openid));
if(empty($saler)){
    $is_hexiao_member=0;
}
if($_W['isajax']){
    if($checkorder['times'] < 1)
    {
//        pdo_update('tg_favorabler',array('status'=>1),array('id'=>$orderno));
        wl_json(0,'该项目核销次数已用完，请勿重复核销！');
    }
    if(pdo_update('tg_favorabler',array('times' => ($checkorder['times'] - 1)),array('id' => $orderno))){
        $data = array();
        $data['uniacid'] = $checkorder['uniacid'];
        $data['favorabler_id'] = $checkorder['id'];
        $data['favorable_id'] = $checkorder['favorable_id'];
        $data['openid'] = $checkorder['openid'];
        $data['check_openid'] = $openid;
        $data['check_time'] = TIMESTAMP;
        pdo_insert('tg_hexiao', $data);
        if ($checkorder['times'] == 1){
            pdo_update('tg_favorabler',array('status' => 1),array('id' => $orderno));
        }
        pdo_update('tg_member' , array('favorable_times +=' => 1) , array('uniacid' => $checkorder['uniacid'] , 'openid' => $checkorder['openid']));
        wl_json(1);
    }else{
        wl_json(0,'核销失败，请重试！');
    }
}
include wl_template('shaoniancheck');
exit();